package wahadlo.nowe.math;

public class Speed implements Function {

	private Double a0;
	private Double beta;
	private Double length;

	public Speed(Double a0, Double beta, Double length) {
		this.a0 = a0;
		this.beta = beta;
		this.length = length;
	}

	public Double getValue(Double... points) {
		Double t;
		if (points != null && points.length > 0) {
			t = points[0];
		} else {
			throw new NullPointerException();
		}

		Double firstA0Part = -beta * a0 * Math.pow(Math.E, (-beta * t));
		Double firstCosPart = Math.cos(Math.sqrt(length / Function.G) * t);

		Double firstPart = firstA0Part * firstCosPart;

		Double secondA0Part = Math.sqrt(length / Function.G) * a0
				* Math.pow(Math.E, (-beta * t));
		Double secondCosPart = Math.sin(Math.sqrt(length / Function.G) * t);

		Double secondPart = secondA0Part * secondCosPart;

		return firstPart + secondPart;
	}

}
